/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.submit;

import java.io.InputStream;

import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.acd.AcdToProgram;
import net.bioteam.appweb.acd.AcdToProgramTest;
import net.bioteam.appweb.model.Parameter;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.model.XmlToProgram;
import net.sf.ehcache.CacheManager;
import junit.framework.TestCase;

public class PerlEvalTest extends TestCase {

	public PerlEvalTest(String name) {
		super(name);
	}

	public void setUp() throws Exception {
		TestConfig.init();
		
	}

	public void tearDown() throws Exception {
		TestConfig.shutdown();
	}

	public static void main(String args[]) {
		PerlEvalTest test = new PerlEvalTest("testPerlEval");
		junit.textui.TestRunner.run(test);
	}
	public void testPerlEval() throws Exception
	{
		Program program;
		Parameter p;
		DefaultCommandLineGenerator generator = new DefaultCommandLineGenerator();
		String cmdline, expected;
		ProgramValueBean bean;
		ProgramBuilder.cache.remove("blastall");
		
		program = ProgramBuilder.getProgram("blastall");
		bean = new ProgramValueBean(program);
		
		bean.setValue("blastall", "blastp");
		bean.setValue("query", "infile");
		bean.setValue("protein_db", "nr");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), null);	
		expected="blastall -p blastp  -d \"nr\"  -i infile  -a 2  -o blastall.txt";
		assertEquals(expected, cmdline.trim());
		
		//boolean 
		bean.setValue("filter", "0");
		bean.setValue("lower_case", "1");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), null);	
		expected="blastall -p blastp  -d \"nr\"  -i infile  -F F  -U T  -a 2  -o blastall.txt";
		assertEquals(expected, cmdline.trim());
		
		bean.setValue("filter", "1");
		bean.setValue("lower_case", "0");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), null);	
		expected="blastall -p blastp  -d \"nr\"  -i infile  -a 2  -o blastall.txt";
		assertEquals(expected, cmdline.trim());
		
		//precond and integer
		bean = new ProgramValueBean(program);
		bean.setValue("blastall", "blastp");
		bean.setValue("query", "infile");
		bean.setValue("protein_db", "nr");
		bean.setValue("end_region", "200");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), null);	
		expected="blastall -p blastp  -d \"nr\"  -i infile  -a 2  -o blastall.txt";
		assertEquals(expected, cmdline.trim());
		
		bean.setValue("start_region", "100");
		cmdline = generator.generateScript((ProgramValueBean) bean
				.myClone(), null);	
		expected="blastall -p blastp  -d \"nr\"  -i infile  -L \"100 200\"  -a 2  -o blastall.txt";
		assertEquals(expected, cmdline.trim());
		
	}
}

